#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

class Solution {
	int n, m;
	vector<int> father;
	vector<int> ene;

	int find(int x)
	{
		return father[x] == x ? x : father[x] = find(father[x]);
	}

	void merge(int x, int y)
	{
		father[find(x)] = find(y);
	}

    public:
	Solution(int n, int m) : n(n), m(m), father(n + 1, 0), ene(n + 1, 0)
	{
		iota(father.begin(), father.end(), 0);
	}

	void run()
	{
		char rel;
		int x, y, ans = 0;

		for (int i = 0; i < m; i++) {
			cin >> rel >> x >> y;
			if (rel == 'E') {
				if (ene[x] == 0) {
					ene[x] = y;
				} else {
					merge(y, ene[x]);
				}

				if (ene[y] == 0) {
					ene[y] = x;
				} else {
					merge(x, ene[y]);
				}
			} else {
				merge(x, y);
			}
		}

		for (int i = 1; i <= n; i++) {
			if (father[i] == i) {
				ans++;
			}
		}

		cout << ans << endl;
	}
};

int main()
{
	int n, m;
        cin >> n >> m;
        Solution s(n, m);
	s.run();
	return 0;
}